<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      数据库上线
      <small>注意环境选择</small>
    </h1>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
      <li class="active">Here</li>
    </ol>
  </section>
  <!-- Main content -->
  <section class="content">

    <div class="row">
      <div class="col-xs-12">

        <%= form_tag '/sql_order/%s' % @db_name.dbname do %>
            <div class="box box-primary">
              <div class="box-header">
                <h3 class="box-title">数据库名：<%= @db_name.dbname %></h3>
              </div>
              <!-- /.box-header -->
              <div class="box-body">
                <div class="form-group<%= @title_error ? ' has-error' : '' %>">
                  <label>上线事由</label>
                  <input type="text" class="form-control" id="sql_title"  name="title"  placeholder="此处输入上线事由（至少四个字符,最长三十字符）" value="<%= params[:titles] %>" autocomplete="off">
                </div>
                <div class="form-group<%= @sql_script_error ? ' has-error' : '' %>">
                  <label>SQL内容</label>
                  <textarea type="Textarea" style="height:150px;resize:none;" id="txt_script" class="form-control"  name="sql_script" placeholder="此处输入sql内容(不超过2万条,超过2万条请选择文件提交)" value="<%= params[:sql_script] %>"  autocomplete="off"></textarea>
                </div>
                <!-- radio -->
                <div class="form-group">
                  <label>环境选择</label>
                  <% @db_envs.each do |env| %>
                      <div class="radio">
                        <label>
                          <input type="radio" name="database_id" value="<%= env.id %>"  checked>
                          <%= env.env %>
                        </label>
                      </div>
                  <%end%>

                </div>
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="button" class="btn btn-primary" id="btn_submit">提交</button>
                <!--<button type="button" class="btn btn-info table_btn" onclick="javascript:history.go(-1);">取消</button>-->
                <!--<button type="submit" class="btn btn-primary">上传文件</button>-->
              </div>

            </div>
            <!-- /.box -->
        <% end %>
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </section>
  <!-- /.content -->
</div><!-- /.content-wrapper -->
</div>


<script type="text/javascript">
  $(function(){
    $('#btn_submit').click(function(){
      if ($('.radio').find("input:checked").parent().text().trim() == '生产') {
        var re = window.confirm('该操作会提交到生产环境，确认继续吗？')
        if (!re) {
          return false;
          document.getElementById("btn_submit").innerHTML=false;
        }

      }
      var sql_title = $('#sql_title').val();
      var sql_title_length = sql_title.length;
      if(sql_title_length > 30){
        alert("上线事由长度不能超过30字符");
        return false;
      }else if(sql_title_length< 4){
        alert("上线事由长度不能少于4个字符");
        return false;
      }
      var txt_script  = $('#txt_script').val();
      var txt_script_length = txt_script.length;
      //var searchArray = txt_script_length.split("\n")
      if(txt_script_length == 0){
        alert("SQL内容不能为空");
        return false;
      }
      else
        var searchArray = txt_script.split("\n")
      if(searchArray.length >20000){
        alert("SQL行数不能超过20000行，如有特殊需求，请联系运维")
        return false;
      }

      $('form').submit();
    });

  });

</script>